#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <memory>

using namespace std;

class QueryResult;

class TextQuery {
public:
    using line_no = vector<string>::size_type;
    TextQuery(ifstream &is);
    QueryResult query(const string &word);

private:
    shared_ptr<vector<string>> file;
    map<string, shared_ptr<set<line_no>>> wordMap;
};

class QueryResult {
    friend ostream &print(ostream &out, const QueryResult &res);
public:
    using line_no = vector<string>::size_type;
    QueryResult(const string w, shared_ptr<vector<string>> f, shared_ptr<set<line_no>> l) : word(w), file(f), lines(l) {};

private:
    string word;
    shared_ptr<vector<string>> file;
    shared_ptr<set<line_no>> lines;
};
